1 Imports System.Data.OleDb
2 Imports System.Text.RegularExpressions
3
4 Public Class frmRegistration
5 Dim st1 As String
6 Sub Reset()
7 txtContactNo.Text = ""
8 txtEmailID.Text = ""
9 txtName.Text = ""
10 txtPassword.Text = ""
11 txtUserID.Text = ""
12 cmbUserType.SelectedIndex = -1
13 chkActive.Checked = True
14 txtUserID.Focus()
15 btnSave.Enabled = True
16 btnUpdate.Enabled = False
17 btnDelete.Enabled = False
18 End Sub
19
20
21
22 Private Sub DeleteRecord()
23
24 Try
25 If txtUserID.Text = "admin" Or txtUserID.Text = "Admin" Then
26 MessageBox.Show("Admin account can not be deleted", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
27 Exit Sub
28 End If
29 Dim RowsAffected As Integer = 0
30 con = New OleDbConnection(cs)
31 con.Open()
32 Dim cl As String = "select UserID from Registration,RestaurantBillingInfo where RestaurantBillingInfo.OperatorID=Registration.UserID and UserID=@d1"
33 cmd = New OleDbCommand(cl)
34 cmd.Connection = con
35 cmd.Parameters.AddWithValue("@d1", txtUserID.Text)
36 rdr = cmd.ExecuteReader()
37 If rdr.Read Then
38 MessageBox.Show("Unable to delete..Already in use in Billing", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
39 If Not rdr Is Nothing Then
40 rdr.Close()
41 End If
42 Exit Sub
43 End If
44 con.Close()
45 con = New OleDbConnection(cs)
46 con.Open()
47 Dim cl1 As String = "select UserID from Registration,KOTGeneration where KOTGeneration.OperatorID=Registration.UserID and UserID=@d1"
48 cmd = New OleDbCommand(cl1)
49 cmd.Connection = con
50 cmd.Parameters.AddWithValue("@d1", txtUserID.Text)
51 rdr = cmd.ExecuteReader()
52 If rdr.Read Then
53 MessageBox.Show("Unable to delete..Already in use in Billing", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
54 If Not rdr Is Nothing Then
55 rdr.Close()
56 End If
57 Exit Sub
58 End If
59 con.Close()
60 con = New OleDbConnection(cs)
61 con.Open()
62 Dim cq As String = "delete from Registration where userid=@d1"
63 cmd = New OleDbCommand(cq)
64 cmd.Parameters.AddWithValue("@d1", txtUserID.Text)
65 cmd.Connection = con
66 RowsAffected = cmd.ExecuteNonQuery()
67 If RowsAffected > 0 Then
68 Dim st As String = "deleted the user '" & txtUserID.Text & "'"
69 LogFunc(lblUser.Text, st)
70 MessageBox.Show("Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
71 Getdata()
72 Reset()
73 Else
74 MessageBox.Show("No Record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information)
75 Reset()
76 End If
77 If con.State = ConnectionState.Open Then
78 con.Close()
79
80 End If
81 Catch ex As Exception
82 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
83 End Try
84 End Sub
85
86 Public Sub Getdata()
87 Try
88 con = New OleDbConnection(cs)
89 con.Open()
90 cmd = New OleDbCommand("SELECT RTRIM(userid), RTRIM(UserType), RTRIM([Password]), RTRIM(RegisteredName), RTRIM(EmailID), RTRIM(ContactNo),RTRIM(Active),JoiningDate from Registration order by JoiningDate", con)
91 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
92 dgw.Rows.Clear()
93 While (rdr.Read() = True)
94 dgw.Rows.Add(rdr(0), rdr(1), (rdr(2)), rdr(3), rdr(4), rdr(5), rdr(6), rdr(7))
95 End While
96 con.Close()
97 Catch ex As Exception
98 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
99 End Try
100 End Sub
101
102
103 Private Sub dgw_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgw.RowPostPaint
104 Dim strRowNumber As String = (e.RowIndex + 1).ToString()
105 Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
106 If dgw.RowHeadersWidth < Convert.ToInt32((size.Width + 20)) Then
107 dgw.RowHeadersWidth = Convert.ToInt32((size.Width + 20))
108 End If
109 Dim b As Brush = SystemBrushes.ControlText
110 e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
111
112 End Sub
113
114 Private Sub frmRegistration_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
115 If e.KeyCode = Keys.Enter Then
116 Me.SelectNextControl(Me.ActiveControl, True, True, True, False) 'for Select Next Control
117 End If
118 End Sub
119
120 Private Sub frmRegistration_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
121 Getdata()
122 End Sub
123
124 Private Sub dgw_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgw.MouseClick
125 Try
126 If dgw.Rows.Count > 0 Then
127 Dim dr As DataGridViewRow = dgw.SelectedRows(0)
128 txtUserID.Text = dr.Cells(0).Value.ToString()
129 TextBox1.Text = dr.Cells(0).Value.ToString()
130 cmbUserType.Text = dr.Cells(1).Value.ToString()
131 txtPassword.Text = dr.Cells(2).Value.ToString()
132 txtName.Text = dr.Cells(3).Value.ToString()
133 txtContactNo.Text = dr.Cells(5).Value.ToString()
134 txtEmailID.Text = dr.Cells(4).Value.ToString()
135 txtEmail.Text = dr.Cells(4).Value.ToString()
136 If dr.Cells(6).Value.ToString() = "Yes" Then
137 chkActive.Checked = True
138 Else
139 chkActive.Checked = False
140 End If
141 btnUpdate.Enabled = True
142 btnDelete.Enabled = True
143 btnSave.Enabled = False
144 End If
145 Catch ex As Exception
146 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
147 End Try
148 End Sub
149
150 Private Sub btnCheckAvailability_Click(sender As System.Object, e As System.EventArgs) Handles btnCheckAvailability.Click
151 If txtUserID.Text = "" Then
152 MessageBox.Show("Please enter user id", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
153 txtUserID.Focus()
154 Return
155 End If
156 Try
157 con = New OleDbConnection(cs)
158 con.Open()
159 Dim ct As String = "select userid from registration where userid=@d1"
160 cmd = New OleDbCommand(ct)
161 cmd.Parameters.AddWithValue("@d1", txtUserID.Text)
162 cmd.Connection = con
163 rdr = cmd.ExecuteReader()
164 If rdr.Read() Then
165 MessageBox.Show("User ID not available", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
166 If (rdr IsNot Nothing) Then
167 rdr.Close()
168 End If
169 Return
170 Else
171 MessageBox.Show("User ID available", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
172 If (rdr IsNot Nothing) Then
173 rdr.Close()
174 End If
175 Return
176 End If
177 Catch ex As Exception
178 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
179 End Try
180 End Sub
181
182 Private Sub btnClose_Click_1(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
183 Dim obj As frmMainMenu = DirectCast(Application.OpenForms("frmMainMenu"), frmMainMenu)
184 obj.lblUser.Text = lblUser.Text
185 Me.Close()
186 End Sub
187
188
189
190 Private Sub btnUpdate_Click(sender As System.Object, e As System.EventArgs) Handles btnUpdate.Click
191 Try
192 If txtUserID.Text = "" Then
193 MessageBox.Show("Please enter user id", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
194 txtUserID.Focus()
195 Return
196 End If
197 If cmbUserType.Text = "" Then
198 MessageBox.Show("Please select user type", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
199 cmbUserType.Focus()
200 Return
201 End If
202 If txtPassword.Text = "" Then
203 MessageBox.Show("Please enter password", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
204 txtPassword.Focus()
205 Return
206 End If
207 If txtName.Text = "" Then
208 MessageBox.Show("Please enter name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
209 txtName.Focus()
210 Return
211 End If
212 If txtEmailID.Text = "" Then
213 MessageBox.Show("Please enter email id", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
214 txtEmailID.Focus()
215 Return
216 End If
217 If txtContactNo.Text = "" Then
218 MessageBox.Show("Please enter contact no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
219 txtContactNo.Focus()
220 Return
221 End If
222 If chkActive.Checked = True Then
223 st1 = "Yes"
224 Else
225 st1 = "No"
226 End If
227 If txtEmail.Text <> txtEmailID.Text Then
228 con = New OleDbConnection(cs)
229 con.Open()
230 Dim ct2 As String = "select EmailID from registration where EmailID=@d1"
231 cmd = New OleDbCommand(ct2)
232 cmd.Parameters.AddWithValue("@d1", txtEmailID.Text)
233 cmd.Connection = con
234 rdr = cmd.ExecuteReader()
235 If rdr.Read() Then
236 MessageBox.Show("Email id Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
237 If (rdr IsNot Nothing) Then
238 rdr.Close()
239 End If
240 Return
241 End If
242 con.Close()
243 End If
244 If chkActive.Checked = True Then
245 st1 = "Yes"
246 Else
247 st1 = "No"
248 End If
249 con = New OleDbConnection(cs)
250 con.Open()
251 Dim cb As String = "update registration set userid=@d1, usertype=@d2,[password]=@d3,RegisteredName=@d4,contactno=@d5,emailid=@d6,[Active]=@d8 where userid=@d7"
252 cmd = New OleDbCommand(cb)
253 cmd.Connection = con
254 cmd.Parameters.AddWithValue("@d1", txtUserID.Text)
255 cmd.Parameters.AddWithValue("@d2", cmbUserType.Text)
256 cmd.Parameters.AddWithValue("@d3", Encrypt(txtPassword.Text.Trim()))
257 cmd.Parameters.AddWithValue("@d4", txtName.Text)
258 cmd.Parameters.AddWithValue("@d5", txtContactNo.Text)
259 cmd.Parameters.AddWithValue("@d6", txtEmailID.Text)
260 cmd.Parameters.AddWithValue("@d7", TextBox1.Text)
261 cmd.Parameters.AddWithValue("@d8", st1)
262 cmd.ExecuteReader()
263 con.Close()
264 Dim st As String = "updated the user '" & txtUserID.Text & "' details"
265 LogFunc(lblUser.Text, st)
266 MessageBox.Show("Successfully updated", "User Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
267 btnUpdate.Enabled = False
268 Getdata()
269 Catch ex As Exception
270 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
271 End Try
272 End Sub
273
274 Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
275 Try
276 If MessageBox.Show("Do you really want to delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
277 DeleteRecord()
278 End If
279 Catch ex As Exception
280 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
281 End Try
282 End Sub
283
284 Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
285 If txtUserID.Text = "" Then
286 MessageBox.Show("Please enter user id", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
287 txtUserID.Focus()
288 Return
289 End If
290 If cmbUserType.Text = "" Then
291 MessageBox.Show("Please select user type", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
292 cmbUserType.Focus()
293 Return
294 End If
295 If txtPassword.Text = "" Then
296 MessageBox.Show("Please enter password", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
297 txtPassword.Focus()
298 Return
299 End If
300 If txtName.Text = "" Then
301 MessageBox.Show("Please enter name", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
302 txtName.Focus()
303 Return
304 End If
305 If txtEmailID.Text = "" Then
306 MessageBox.Show("Please enter email id", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
307 txtEmailID.Focus()
308 Return
309 End If
310 If txtContactNo.Text = "" Then
311 MessageBox.Show("Please enter contact no.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
312 txtContactNo.Focus()
313 Return
314 End If
315
316 Try
317 con = New OleDbConnection(cs)
318 con.Open()
319 Dim ct As String = "select userid from registration where userid=@d1"
320 cmd = New OleDbCommand(ct)
321 cmd.Parameters.AddWithValue("@d1", txtUserID.Text)
322 cmd.Connection = con
323 rdr = cmd.ExecuteReader()
324 If rdr.Read() Then
325 MessageBox.Show("user id Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
326 txtUserID.Text = ""
327 txtUserID.Focus()
328 If (rdr IsNot Nothing) Then
329 rdr.Close()
330 End If
331 Return
332 End If
333 con.Close()
334 con = New OleDbConnection(cs)
335 con.Open()
336 Dim ct2 As String = "select EmailID from registration where EmailID=@d1"
337 cmd = New OleDbCommand(ct2)
338 cmd.Parameters.AddWithValue("@d1", txtEmailID.Text)
339 cmd.Connection = con
340 rdr = cmd.ExecuteReader()
341 If rdr.Read() Then
342 MessageBox.Show("Email id Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
343 If (rdr IsNot Nothing) Then
344 rdr.Close()
345 End If
346 Return
347 End If
348 con.Close()
349 If chkActive.Checked = True Then
350 st1 = "Yes"
351 Else
352 st1 = "No"
353 End If
354 con = New OleDbConnection(cs)
355 con.Open()
356 Dim cb As String = "insert into Registration(userid, UserType, [Password],RegisteredName, ContactNo, EmailID,JoiningDate,Active) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,#" & System.DateTime.Now & "#,@d8)"
357 cmd = New OleDbCommand(cb)
358 cmd.Connection = con
359 cmd.Parameters.AddWithValue("@d1", txtUserID.Text)
360 cmd.Parameters.AddWithValue("@d2", cmbUserType.Text)
361 cmd.Parameters.AddWithValue("@d3", Encrypt(txtPassword.Text.Trim()))
362 cmd.Parameters.AddWithValue("@d4", txtName.Text)
363 cmd.Parameters.AddWithValue("@d5", txtContactNo.Text)
364 cmd.Parameters.AddWithValue("@d6", txtEmailID.Text)
365 cmd.Parameters.AddWithValue("@d8", st1)
366 cmd.ExecuteReader()
367 con.Close()
368 Dim st As String = "added the new user '" & txtUserID.Text & "'"
369 LogFunc(lblUser.Text, st)
370 MessageBox.Show("Successfully Registered", "User", MessageBoxButtons.OK, MessageBoxIcon.Information)
371 btnSave.Enabled = False
372 Getdata()
373 Reset()
374 Catch ex As Exception
375 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
376 End Try
377 End Sub
378
379 Private Sub btnNew_Click(sender As System.Object, e As System.EventArgs) Handles btnNew.Click
380 Reset()
381 End Sub
382
383 Private Sub dgw_CellFormatting(sender As System.Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgw.CellFormatting
384 If (e.ColumnIndex = 2) AndAlso e.Value IsNot Nothing Then
385 dgw.Rows(e.RowIndex).Tag = e.Value
386 e.Value = New [String]("●"c, e.Value.ToString().Length)
387 End If
388 End Sub
389
390 Private Sub dgw_EditingControlShowing(sender As System.Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgw.EditingControlShowing
391 If dgw.CurrentCell.ColumnIndex = 2 Then
392 'select target column
393 Dim textBox As TextBox = TryCast(e.Control, TextBox)
394 If textBox IsNot Nothing Then
395 textBox.UseSystemPasswordChar = True
396 End If
397 Else
398 Dim textBox As TextBox = TryCast(e.Control, TextBox)
399 If textBox IsNot Nothing Then
400 textBox.UseSystemPasswordChar = False
401 End If
402 End If
403 End Sub
404
405 Private Sub txtEmailID_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtEmailID.KeyPress
406 Dim ac As String = "@"
407 If e.KeyChar <> ChrW(Keys.Back) Then
408 If Asc(e.KeyChar) < 97 Or Asc(e.KeyChar) > 122 Then
409 If Asc(e.KeyChar) <> 46 And Asc(e.KeyChar) <> 95 Then
410 If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
411 If ac.IndexOf(e.KeyChar) = -1 Then
412 e.Handled = True
413
414 Else
415
416 If txtEmailID.Text.Contains("@") And e.KeyChar = "@" Then
417 e.Handled = True
418 End If
419
420 End If
421
422
423 End If
424 End If
425 End If
426
427 End If
428 End Sub
429
430 Private Sub txtEmailID_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles txtEmailID.Validating
431 Dim pattern As String = "^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$"
432 Dim match As System.Text.RegularExpressions.Match = Regex.Match(txtEmailID.Text.Trim(), pattern, RegexOptions.IgnoreCase)
433 If (match.Success) Then
434 Else
435 MessageBox.Show("Please enter a valid email id", "Checking")
436 txtEmailID.Clear()
437 End If
438 End Sub
439 End Class